import 'package:baselib/utils/color_base_util.dart';
import 'package:baselib/utils/px_base_util.dart';
import 'package:baselib/utils/string_base_util.dart';
import 'package:baselib/widgets/gradient_card_view.dart';
import 'package:flutter/material.dart';

class CommMessageGradientDialog extends Dialog {
  String message;

  String negativeText;
  String positiveText;
  Function onCloseEvent;
  Function onPositivePressEvent;
  bool isTouchOutSideDissmiss;
  bool isTouchKeyBackDissmiss;

  CommMessageGradientDialog({
    Key key,
    @required this.message,
    this.negativeText,
    this.positiveText,
    this.onPositivePressEvent,
    this.isTouchOutSideDissmiss = true,
    this.isTouchKeyBackDissmiss = true,
    @required this.onCloseEvent,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () {
        if (isTouchKeyBackDissmiss) {
          Navigator.of(context).pop();
        }
      },
      child: GestureDetector(
        onTap: () {
          if (isTouchOutSideDissmiss) {
            Navigator.of(context).pop();
          }
        },
        child: new Material(
          type: MaterialType.transparency,
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              GestureDetector(
                onTap: () {},
                child: GradientCardView(
                  elevation: PxBaseUtil().px_0,
                  margin: EdgeInsets.only(
                    left: PxBaseUtil().px_30,
                    right: PxBaseUtil().px_30,
                  ),
                  padding: EdgeInsets.only(),
                  borderRadius: BorderRadius.circular(PxBaseUtil().px_20),
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(PxBaseUtil().px_20),
                      color: ColorBaseUtil().color_2F4072,
                    ),
                    padding: EdgeInsets.only(
                      left: PxBaseUtil().px_35,
                      right: PxBaseUtil().px_35,
                      top: PxBaseUtil().px_30,
                      bottom: PxBaseUtil().px_30,
                    ),
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          child: Text(
                            '${message ?? ''}',
                            textAlign: TextAlign.center,
                            style: TextStyle(
                                color: ColorBaseUtil().color_white,
                                fontSize: PxBaseUtil().px_17),
                          ),
                        ),
                        SizedBox(
                          height: PxBaseUtil().px_35,
                        ),
                        Container(
                          child: Row(
                            children: [
                              Expanded(
                                  child: GestureDetector(
                                onTap: () {
                                  if (onCloseEvent != null) onCloseEvent();
                                },
                                child: GradientCardView(
                                    elevation: PxBaseUtil().px_0,
                                    borderRadius: BorderRadius.circular(
                                        PxBaseUtil().px_18),
                                    child: Container(
                                      height: PxBaseUtil().px_35,
                                      decoration: BoxDecoration(
                                        borderRadius: BorderRadius.circular(
                                            PxBaseUtil().px_18),
                                        color:
                                            ColorBaseUtil().color_transparent,
                                      ),
                                      child: Center(
                                        child: Text(
                                          negativeText ??
                                              StringBaseUtil().Cancel,
                                          style: TextStyle(
                                              color:
                                                  ColorBaseUtil().color_white,
                                              fontSize: PxBaseUtil().px_14),
                                        ),
                                      ),
                                    )),
                              )),
                              SizedBox(
                                width: PxBaseUtil().px_30,
                              ),
                              Expanded(
                                  child: GestureDetector(
                                    onTap: () {
                                      if (onPositivePressEvent != null)
                                        onPositivePressEvent();
                                    },
                                    child: GradientCardView(
                                        elevation: PxBaseUtil().px_0,
                                        borderRadius: BorderRadius.circular(
                                            PxBaseUtil().px_18),
                                        child: Container(
                                          height: PxBaseUtil().px_35,
                                          decoration: BoxDecoration(
                                            borderRadius: BorderRadius.circular(
                                                PxBaseUtil().px_18),
                                            color: ColorBaseUtil().color_2F4072,
                                          ),
                                          child: Center(
                                            child: Text(
                                              positiveText ??
                                                  StringBaseUtil().Confirm,
                                              style: TextStyle(
                                                  color: ColorBaseUtil()
                                                      .color_white,
                                                  fontSize: PxBaseUtil().px_14),
                                            ),
                                          ),
                                        )),
                                  )
                              ),
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
